package com.sichen.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ES的配置包
 * <p>Created with IntelliJ IDEA.
 * <p>Author: 思尘
 * <p>Created time: 2022-09-11 17:35
 * <p>Version: V1.0
 */
@Configuration
public class ElasticSearchConfig {

    @Bean
    public RestHighLevelClient EsRestClient(){
        return new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.63.10", 9200, "http")));
    }

    /*@Bean
    public RestHighLevelClient restHighLevelClient(){
        return new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.63.10:9200")));
    }
    */
    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        /*builder.addHeader("Authorization", "Bearer " + TOKEN);
        builder.setHttpAsyncResponseConsumerFactory(
                new HttpAsyncResponseConsumerFactory
                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));*/
        COMMON_OPTIONS = builder.build();
    }
}
